<?php

class View_Helper_Routes extends Model3_View_Helper
{

    public function summary($em, $routeId)
    {
        $routeRepos = $em->getRepository('DefaultDb_Entities_Route');
        $resumen = $routeRepos->getDetailsRoute($routeId);
        ?>
        <div>
            Nombre: <strong><?php echo $resumen['route_name']; ?></strong>
        </div>
        <?php if ($resumen['total'] > 0): ?>
            <div>
                Total de <abbr title="puntos de venta">pv</abbr> y <abbr title="centros de intercambio">ci</abbr>: <strong><?php echo $resumen['total']; ?></strong>
            </div>
            <div>
                Puntos de venta: <strong><?php echo $resumen['pv']; ?></strong>
                <span class="glyphicon glyphicon-record" title="Puntos de venta">
            </div>
            <div>
                Centros de intercambio: <strong><?php echo $resumen['ci']; ?></strong>
                <span class="glyphicon glyphicon-transfer" title="Centro de intercambio">
            </div>
            <div>
                Puntos de visita obligatoria: <strong><?php echo $resumen['requireds']; ?></strong>
                <span class="glyphicon glyphicon-map-marker" title="Punto de visita obligatoria"></span>
            </div>
            <div>
                Minutos totales de la ruta: <strong><?php echo $resumen['minutes']; ?></strong>
            </div>
            <div>
                Estatus de la ruta: <strong><?php echo $resumen['str_close']; ?></strong>
            </div>
        <?php else: ?>
            <br/>
            <div class="alert alert-info">
                La ruta aún no tiene puntos de venta / centros de intercambio.
            </div>
        <?php
        endif;
    }

    public function points($em, $routeId)
    {
        $rpRepos = $em->getRepository('DefaultDb_Entities_RoutePoint');
        $routeRepos = $em->getRepository('DefaultDb_Entities_Route');

        $routePoints = $rpRepos->getRoutesPointsByRoute($routeId);
        $route = $routeRepos->find($routeId);
        $numPoints = count($routePoints);
        ?>
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">Puntos de venta / centros de intercambio</h3>
            </div>
            <?php if ($numPoints > 0): ?>
                <table class="table table-striped table-bordered table-condensed">
                    <thead>
                        <tr>
                            <th>Nombre</th>
                            <th>Tipo</th>
                            <th class="text-center">Tiempo</th>
                            <?php if ($route->getClose() == 0): ?>
                                <th class="text-center">Subir</th>
                                <th class="text-center">Bajar</th>
                                <th class="text-center">Eliminar</th>
                                <th class="text-center">Editar</th>
                            <?php endif; ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($routePoints as $key => $rp): ?>
                            <tr>
                                <td class="uppercase"><?php echo '[' . $rp['code'] . '] ' . $rp['name']; ?></td>
                                <td class="uppercase">
                                    <?php
                                    if ($rp['type'] == DefaultDb_Entities_Point::TYPE_SALE_POINT)
                                    {
                                        echo 'Punto de Venta';
                                        echo '&nbsp;<span class="glyphicon glyphicon-record" title="Puntos de venta">';
                                    }
                                    else
                                    {
                                        echo 'Centro de Intercambio';
                                        echo '&nbsp;<span class="glyphicon glyphicon-transfer" title="Centro de intercambio"></span>';
                                    }
                                    if ($rp['required'] == 1)
                                    {
                                        echo '&nbsp;<span class="glyphicon glyphicon-map-marker" title="Punto de visita obligatoria"></span>';
                                    }
                                    ?>
                                </td>
                                <td class="text-center">
                                    <?php echo date_format($rp['arrivalTime'], 'i'); ?>
                                </td>
                                <?php if ($route->getClose() == 0): ?>
                                    <td class="text-center">
                                        <?php if ($key > 1): ?>
                                            <a href="<?php
                                            echo $this->_view->url(array(
                                                'action' => 'stepUpRoutePoint', 'routePointId' => $rp['id']), true);
                                            ?>">
                                                <span class="glyphicon glyphicon-arrow-up"></span>
                                            </a>
                                        <?php endif; ?>
                                    </td>
                                    <td class="text-center">
                                        <?php if ($key > 0 && $key < $numPoints - 1): ?>
                                            <a href="<?php
                                            echo $this->_view->url(array(
                                                'action' => 'stepDownRoutePoint',
                                                'routePointId' => $rp['id']), true);
                                            ?>">
                                                <span class="glyphicon glyphicon-arrow-down"></span>
                                            </a>
                                        <?php endif; ?>
                                    </td>
                                    <td class="text-center">
                                        <?php if ($key > 0 && $key != $numPoints - 1): ?>
                                            <a href="<?php
                                            echo $this->_view->url(array(
                                                'action' => 'deleteRoutePoint', 'routePointId' => $rp['id']), true);
                                            ?>">
                                                <span class="glyphicon glyphicon-remove"></span>
                                            </a>
                                        <?php endif; ?>
                                    </td>
                                    <td class="text-center">
                                        <a href="<?php
                                        echo $this->_view->url(array(
                                            'action' => 'editRoutePoint', 'routePointId' => $rp['id']), true);
                                        ?>">
                                            <span class="glyphicon glyphicon-edit"></span>
                                        </a>
                                    </td>
                                <?php endif; ?>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <div class="panel-body">
                    <br/>
                    <div class="alert alert-info">
                        La ruta aún no tiene puntos de venta / centros de intercambio.
                    </div>
                </div>
            <?php endif; ?>
        </div>
        <?php
    }

    public function listPoints($em, $routeId)
    {
        $rpRepos = $em->getRepository('DefaultDb_Entities_RoutePoint');
        $routePoints = $rpRepos->getRoutesPointsByRoute($routeId);
        $numPoints = count($routePoints);
        ?>
        <?php if ($numPoints > 0): ?>
            <ol style="width: 100%; overflow: hidden;">
                <?php foreach ($routePoints as $rp): ?>
                    <li style="list-style: decimal; margin-left: 20px; ">
                        <strong>[<?php echo $rp['code']; ?>]</strong> <?php echo $rp['name']; ?>
                    </li>
                <?php endforeach; ?>
            </ol>
        <?php else: ?>
            <div class="alert alert-info">
                La ruta aún no tiene puntos de venta / centros de intercambio.
            </div>
        <?php
        endif;
    }

}

